package com.itheima.inetaddress;

import javax.swing.*;
import java.io.*;
import java.net.IDN;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo11 {
    public static void main(String[] args) throws IOException {
        //创建服务器
        ServerSocket ss = new ServerSocket(10000);

        //创建线程池对象
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(
                3,//核心线程池
                10,//线程池的最大总数量
                60,//临时线程空闲时间
                TimeUnit.MINUTES,//单位
                new ArrayBlockingQueue<>(5),//允许多少个线程排队
                Executors.defaultThreadFactory(),//创建线程的方式
                new ThreadPoolExecutor.AbortPolicy()//任务拒绝策略

        );

        while (true) {

            //等待发送的数据
            Socket accept = ss.accept();

            Thread thread = new Thread(accept);

            //new java.lang.Thread(thread).start();



            tpe.submit(thread);


        }

        //ss.close();

    }
}
